package com.itheima.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.itheima.service.MaterialService;
import io.minio.errors.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * @author yunfei
 * @date 2022年10月16日 17:17
 */
@RestController
@RequestMapping("/api/v1/material/")
public class MaterialController {

    @Autowired
    private MaterialService materialService;

    /**
     * 素材图片上传
     * @param multipartFile
     * @return
     * @throws IOException
     * @throws InvalidResponseException
     * @throws InvalidKeyException
     * @throws NoSuchAlgorithmException
     * @throws ServerException
     * @throws InternalException
     * @throws XmlParserException
     * @throws InvalidBucketNameException
     * @throws InsufficientDataException
     * @throws ErrorResponseException
     */
    @PostMapping("upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile) throws IOException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, ServerException, InternalException, XmlParserException, InvalidBucketNameException, InsufficientDataException, ErrorResponseException {
        return materialService.uploadPic(multipartFile);
    }


    /**
     * 素材分页查询
     */
    @PostMapping("list")
    public ResponseResult materialList(@RequestBody WmMaterialDto materialDto) {
        return materialService.materialList(materialDto);
    }
}
